# 依赖注入工具
from fastapi import Depends, HTTPException, status
from typing import Optional

# 示例：API 密钥验证依赖（可选）
def verify_api_key(api_key: Optional[str] = None) -> bool:
    """验证API密钥（示例）"""
    # 这里可以实现实际的API密钥验证逻辑
    # 目前只是一个示例，实际项目中可以根据需要实现
    if api_key is None:
        return True  # 暂时不强制要求API密钥
    
    # 示例：检查API密钥是否有效
    valid_keys = ["test-key", "demo-key"]
    return api_key in valid_keys

# 示例：分页参数依赖
class PaginationParams:
    def __init__(self, page: int = 1, size: int = 10):
        if page < 1:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail="页码必须大于0"
            )
        if size < 1 or size > 100:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail="每页大小必须在1-100之间"
            )
        self.page = page
        self.size = size
        self.offset = (page - 1) * size

def get_pagination_params(page: int = 1, size: int = 10) -> PaginationParams:
    """获取分页参数"""
    return PaginationParams(page=page, size=size) 